﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace WYFast.IdentityServer
{
    public static class IdentityBuilder
    {

        public static void AddIdentityService(this IServiceCollection services, Action<MvcOptions> option = null)
        {

            // 使用内存存储，密钥，客户端和资源来配置身份服务器。
            services.AddIdentityServer()
                .AddDeveloperSigningCredential()//添加开发人员签名凭据  临时签名凭据

                .AddInMemoryIdentityResources(Id4Config.GetIdentityResources()) //读取身份资源列表
                .AddInMemoryApiResources(Id4Config.GetResources())//读取API资源列表
                .AddInMemoryClients(Id4Config.GetClients())
                .AddTestUsers(TestUsers.Users)//添加内存 临时 用户 client

                .AddResourceOwnerValidator<ResourceOwnerPasswordValidator>()//用户校验
                .AddProfileService<ProfileService>()
            ;
            //services.AddTransient<IdentityServer4.Services.IProfileService, ProfileService>();

        }
    }
}
